package com.ymatou.iapi.thirdpartysync.testcase;

import java.util.Arrays;

import org.junit.After;

import com.ymatou.iapi.productmanager.parameter.product.AddSellerProductRequest;
import com.ymatou.iapi.thirdpartysync.parameter.*;
import com.ymatou.iapi.thirdpartysync.service.*;
import org.junit.AfterClass;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Test;
import org.junit.experimental.categories.Category;

import com.ymt.core.tool.Logger;
import com.ymt.utils.annotation.*;
import com.ymt.utils.tag.*;
import com.ymttest.business.service.ProductManagerCallServiceV2;
import com.ymttest.business.service.ProductManagerCallServiceV3;
import com.ymttest.business.service.ThirdpartysyncCallService;
import com.ymttest.utils.EnvSetup;
/**
*批量查询推广商品状态Test
*FreeMaker Template自动生成代码
*/
@TestSuite
public class Ts_GetProductStatus{
	private static GetProductStatusBean getproductstatusBean;
	private static GetProductStatusCall getproductstatusCall;
	private static int sellerId = 288484;
	private static String sellerName = EnvSetup.getData("productsellername");
	@BeforeClass
	public static void setUp() {
		Logger.createResultFile("批量查询推广商品状态Test");
	}

	@Before
	public void caseUp() {
		getproductstatusBean=new GetProductStatusBean();
		getproductstatusCall=new GetProductStatusCall();
	}

	@AfterClass
	public static void tearDown() {
		Logger.generateResult(getproductstatusCall.getOpurl());
	}

	@After
	public void caseDown() {
		Logger.end();
	}
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_GetProductStatus_001() {
		Logger.start(true,"查询推广中商品状态，成功");
		try {
			AddSellerProductRequest addProdReq = ProductManagerCallServiceV3.initAddSellerProductRequest(sellerId);
			String productId = ProductManagerCallServiceV2.addNewProduct(addProdReq).get("Data").getAsJsonObject()
					.get("ProductId").getAsString();
			Thread.sleep(500);
			//添加推广商品
			ThirdpartysyncCallService.insertPromotionProduct(productId, sellerId, 0.03);
			Thread.sleep(2000);
			ThirdpartysyncCallService.GetDouyinProductInfo(productId);
			getproductstatusBean.setProductIds(Arrays.asList(productId));
			getproductstatusCall.setData(getproductstatusBean);
			getproductstatusCall.callService();			
			Logger.verifyEquals(true, getproductstatusCall.getJsonObject().get("success").getAsBoolean(), "验证返回");
			Logger.verifyEquals(1, getproductstatusCall.getJsonObject().getAsJsonObject("data").getAsJsonObject("productList").get(productId).getAsInt(), "验证返回");
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_GetProductStatus_002() {
		Logger.start(true,"查询推广中和为推广的商品状态，成功");
		try {
			AddSellerProductRequest addProdReq = ProductManagerCallServiceV3.initAddSellerProductRequest(sellerId);
			String productId = ProductManagerCallServiceV2.addNewProduct(addProdReq).get("Data").getAsJsonObject()
					.get("ProductId").getAsString();
			Thread.sleep(500);
			//添加推广商品
			ThirdpartysyncCallService.insertPromotionProduct(productId, sellerId, 0.03);
			Thread.sleep(2000);
			ThirdpartysyncCallService.GetDouyinProductInfo(productId);
			getproductstatusBean.setProductIds(Arrays.asList(productId,"123"));
			getproductstatusCall.setData(getproductstatusBean);
			getproductstatusCall.callService();			
			Logger.verifyEquals(true, getproductstatusCall.getJsonObject().get("success").getAsBoolean(), "验证返回");
			Logger.verifyEquals(1, getproductstatusCall.getJsonObject().getAsJsonObject("data").getAsJsonObject("productList").get(productId).getAsInt(), "验证返回");
			Logger.verifyEquals(0, getproductstatusCall.getJsonObject().getAsJsonObject("data").getAsJsonObject("productList").get("123").getAsInt(), "验证返回");
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	
	
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_GetProductStatus_003() {
		Logger.start(true,"未推广的商品状态，成功");
		try {
			getproductstatusBean.setProductIds(Arrays.asList("123"));
			getproductstatusCall.setData(getproductstatusBean);
			getproductstatusCall.callService();			
			Logger.verifyEquals(true, getproductstatusCall.getJsonObject().get("success").getAsBoolean(), "验证返回");
			Logger.verifyEquals(0, getproductstatusCall.getJsonObject().getAsJsonObject("data").getAsJsonObject("productList").get("123").getAsInt(), "验证返回");
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	
	
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_GetProductStatus_004() {
		Logger.start(true,"productid为空，成功");
		try {
//			getproductstatusBean.setProductIds(Arrays.asList("123"));
			getproductstatusCall.setData(getproductstatusBean);
			getproductstatusCall.callService();			
			Logger.verifyEquals(false, getproductstatusCall.getJsonObject().get("success").getAsBoolean(), "验证返回");
			Logger.verifyEquals(true, getproductstatusCall.getJsonObject().get("data").isJsonNull(), "验证返回");
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	
	
}